//
//  TTZuanshiLeftViewCell.m
//  TaoTuo
//
//  Created by LG on 2020/10/14.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTZuanshiLeftViewCell.h"

@interface TTZuanshiLeftViewCell ()

@property (nonatomic, strong) UIImageView *leftImgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) CAShapeLayer *bgLayer;

@property (nonatomic, strong) CAShapeLayer *whiteLayer;

@end

@implementation TTZuanshiLeftViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        [self setupSubviews];
        self.backgroundColor = UIColorHex(#F5F5F5);
        
    }
    
    return self;
}

- (void)setTitle:(NSString *)title
{
    _title = title;
    
    self.titleLabel.text = title;
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    UIColor *bgColor = UIColor.whiteColor;
    UIFont *font = [UIFont boldSystemFontOfSize:17];
    if (!selected) {
        bgColor = UIColorHex(#F5F5F5);
        font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    }
    
    self.leftImgView.hidden = !selected;
    self.whiteLayer.hidden = !selected;
    
    self.bgLayer.fillColor = bgColor.CGColor;
    self.titleLabel.font = font;
}

- (void)setupSubviews
{
    // 圆角的小白块
    _bgLayer = [CAShapeLayer layer];
    _bgLayer.path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 90, 50) byRoundingCorners:UIRectCornerTopLeft | UIRectCornerBottomLeft cornerRadii:CGSizeMake(13, 13)].CGPath;
    [self.contentView.layer addSublayer:_bgLayer];
    
    
    _leftImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"zs_left_shuxian"]];
    [self.contentView addSubview:_leftImgView];
    [_leftImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.centerY.equalTo(self.contentView);
    }];
    
    _titleLabel = [UILabel labelWithTitle:@"" color:UIColorHex(#333333) font:[UIFont systemFontOfSize:15 weight:UIFontWeightMedium]];
    [self.contentView addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.contentView);
    }];
    
    // 下面的弧线的小白块
    _whiteLayer = [CAShapeLayer layer];
    [self.contentView.layer addSublayer:_whiteLayer];
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(60, 50)];
    [path addArcWithCenter:CGPointMake(75, 65) radius:15 startAngle:-M_PI_2 endAngle:0 clockwise:YES];
    [path addLineToPoint:CGPointMake(90, 50)];
    [path closePath];
    _whiteLayer.fillColor = UIColor.whiteColor.CGColor;
    _whiteLayer.path = path.CGPath;

    
}


@end
